﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Net.Mail;
using System.Configuration;
using Logger;

public partial class LienHe : System.Web.UI.Page
{
    public string noidung = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {


            GioiThieuDataSet gioithieuds = new GioiThieuDataSet();
            GioiThieuHelper gioithieuhelper = new GioiThieuHelper();
            gioithieuds = gioithieuhelper.LoadGioiThieuViTri("LienHe");
            noidung = gioithieuds.GioiThieu[0].NoiDung;

        }
    }

    protected void btnGui_Click(object sender, EventArgs e)
    {
        if (rpHash(Request.Form["txtMaXacNhan"]) == Request.Form["txtMaXacNhanHash"])
        {
            if (Send_Email(txtEmail.Text, "iton@iton.com.vn", txtTenCongTy.Text + " - " + txtTieuDe.Text, txtNoiDung.Text + "<br /><br />--------------------------------------------------<br />Tên: " + txtTenCongTy.Text + "<br />Địa chỉ: " + txtDiaChi.Text + "<br />Điện thoại: " + txtSoDienThoai.Text + "<br />Email: " + txtEmail.Text, "mail.iton.com.vn"))
            {
                ClientScript.RegisterStartupScript(typeof(Page), "testScript", "thanhcong()", true);
            }
            else
            {
                ClientScript.RegisterStartupScript(typeof(Page), "testScript", "thatbai()", true);

            }
        }
        else
        {
            lblthanhpho0.Visible = true;
            lblthanhpho0.ForeColor = System.Drawing.Color.Red;
            lblthanhpho0.Font.Bold = true;
            return;
        }
    }

    private string rpHash(string value)
    {
        int hash = 5381;
        value = value.ToUpper();
        for (int i = 0; i < value.Length; i++)
        {
            hash = ((hash << 5) + hash) + value[i];
        }
        return hash.ToString();
    }

    public static bool Send_Email(string emailfrom, string emailto, string subject, string body, string smtphost)
    {
        bool success = false;
        try
        {
            MailMessage message = new MailMessage();
            message.From = new MailAddress(emailfrom);
            message.To.Add(new MailAddress(emailto));
            message.Subject = subject;
            message.Body = body;
            message.IsBodyHtml = true;
            SmtpClient client = new SmtpClient();
            client.Host = smtphost;
            client.Send(message);
            success = true;
        }
        catch (Exception ex)
        {
        }
        return success;
    }
}